package com.yunhe.policyfulfillment.authority.controller;

import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.mybatis.PageResult;
import com.yunhe.policyfulfillment.authority.domain.PolicyCompanyUser;
import com.yunhe.policyfulfillment.authority.model.AppealAndSatisfaction;
import com.yunhe.policyfulfillment.authority.model.ChangePassword;
import com.yunhe.policyfulfillment.authority.service.PolicyCompanyUserService;
import com.yunhe.policyfulfillment.policyful.domain.Appeal;
import com.yunhe.policyfulfillment.policyful.domain.AppealSatisfaction;
import com.yunhe.policyfulfillment.policyful.model.AppealCondition;
import com.yunhe.policyfulfillment.policyful.service.AppealSatisfactionService;
import com.yunhe.policyfulfillment.policyful.service.AppealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;


/**
 * @ClassName PersonalCenterController
 * @Description TODO
 * @Author HeTao
 * @Date 2021/9/17 10:47
 * @Version 1.0
 **/
@Api(value = "PersonalCenter", description = "Model_PersonalCente", tags = {"个人中心"})
@RestController
@RequestMapping(value = "/personalCenter")
public class PersonalCenterController {

    @Autowired
    private PolicyCompanyUserService policyCompanyUserService;

    @Autowired
    private AppealService appealService;

    @Autowired
    private AppealSatisfactionService appealSatisfactionService;

    @ApiOperation("查询企业用户信息")
    @GetMapping(value = "/findPolicyCompanyUserById")
    public ResponseEntity<ResultObject<PolicyCompanyUser>> findPolicyCompanyUserById(@RequestParam(value = "id",required = true) Integer id){
        return new ResponseEntity<>(new ResultObject(policyCompanyUserService.searchPolicyCompanyUserByPrimaryKey(id)), HttpStatus.OK);
    }

    @ApiOperation("修改密码")
    @PostMapping(value = "/changePolicyCompanyUserPassword")
    public ResponseEntity<ResultObject> changePolicyCompanyUserPassword(@RequestBody ChangePassword changePassword) throws ArgumentErrorException {
        policyCompanyUserService.changePolicyCompanyUserPassword(changePassword);
        return new ResponseEntity<>(new ResultObject(), HttpStatus.OK);
    }

    @ApiOperation("修改企业用户信息")
    @PostMapping(value = "/editPolicyCompanyUser")
    public ResponseEntity<ResultObject> editPolicyCompanyUser(@RequestBody PolicyCompanyUser policyCompanyUser){
        policyCompanyUserService.updatePolicyCompanyUserByPrimaryKeySelective(policyCompanyUser);
        return new ResponseEntity<>(new ResultObject(), HttpStatus.OK);
    }

    @ApiOperation("根据条件查询诉求（个人中心）")
    @PostMapping("/getAppealByConditionPersonalCenter")
    public ResponseEntity<ResultObject<List<Appeal>>> getAppealByConditionPersonalCenter(@RequestBody AppealCondition appealCondition) throws ParseException, ArgumentErrorException {
        PageResult result = appealService.getAppealByConditionPersonalCenter(appealCondition);
        return new ResponseEntity<>(new ResultObject(result),HttpStatus.OK);
    }

    @ApiOperation("查看诉求")
    @GetMapping(value = "/viewAppealById")
    public ResponseEntity<ResultObject<AppealAndSatisfaction>> viewAppealById(@RequestParam(value = "appealId",required = true) long appealId){
        return new ResponseEntity<>(new ResultObject(appealService.findAppealAndSatisfactionById(appealId)), HttpStatus.OK);
    }

    @ApiOperation("新增诉求满意度")
    @PostMapping("/createAppealSatisfaction")
    public ResponseEntity<ResultObject> createAppealSatisfaction(@RequestBody AppealSatisfaction appealSatisfaction) throws ArgumentErrorException {
        appealSatisfactionService.createAppealSatisfaction(appealSatisfaction);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

}
